home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 8: LINUX Games
/
Linux Cubed Series 8 - LINUX Games.iso
/
games
/
video
/
trojka.tgz
/
trojka.tar
/
trojka
/
scan.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-25
|
3KB
|
160 lines
/*
* @(#) scan.c - scan functions for trojka
* created: 4.iii.1992
* last update: 6.iii.1992
*/
#include <curses.h>
#include "trojka.h"
int scan(),
fieldscan(),
explode(),
shifblocks(),
shiftdown(),
getstacklevel(),
isempty(),
reset_f();
extern unsigned long
score,
wipes;
extern char
field[VIRT_XSIZE][VIRT_YSIZE];
extern int stacklevel;
char f[VIRT_XSIZE][VIRT_YSIZE];
/* shadow matrix, where 'tagged' blocks are kept */
int scan()
{
int wipe_bonus, wipe_count, wiped;
wipe_bonus = 1;
wipe_count = 0;
while((wiped = fieldscan()) > 0) {
explode();
delay(100);
shiftblocks();
wipe_bonus *= 2;
score += (unsigned long)(wipe_bonus * wiped * 10);
showscore();
wipe_count++;
if(((int)wipe_count % TROJKA) == 0)
handletrojka(wipe_count); /* trojka ! */
wipes++;
}
return(stacklevel);
}
int fieldscan()
{
int x, y, wiped, left, right;
stacklevel = getstacklevel();
wiped = 0;
left = 0 + 1;
right = VIRT_XSIZE - 1;
for(x = left; x < right; x++)
for(y = stacklevel; y >= PLM_BOTTOM; y--) {
if(field[x][y] > 0) {
/* "\" */ if ((field[x-1][y-1] == field[x][y])
&& (field[x][y] == field[x+1][y+1])) {
f[x-1][y-1] = f[x+1][y+1] = f[x][y] = TAGGED;
wiped++;
}
/* "/" */ if ((field[x-1][y+1] == field[x][y])
&& (field[x][y] == field[x+1][y-1])) {
f[x-1][y+1] = f[x][y] = f[x+1][y-1] = TAGGED;
wiped++;
}
/* "--" */ if ((field[x-1][y] == field[x][y])
&& (field[x][y] == field[x+1][y])) {
f[x-1][y] = f[x+1][y] = f[x][y] = TAGGED;
wiped++;
}
}
}
return(wiped * 3);
}
int explode() /* make fancy stars */
{
int x,y;
for(x = 0; x < VIRT_XSIZE; x++)
for(y = stacklevel; y > 0; y--)
if(f[x][y] == TAGGED)
makestars(x, y);
}
int shiftblocks()
{
int x, y;
for(x = 0; x < VIRT_XSIZE; x++)
for(y = stacklevel; y > 0; y--)
if(f[x][y] == TAGGED) {
shiftdown(x, y);
f[x][y] = CLEAR;
}
refresh();
}
int shiftdown(x, y) /* both visual and virtual */
int x, y;
{
while(field[x][y] != CLEAR) {
field[x][y] = field[x][y+1];
makeblock(x, y, field[x][y]);
y++;
}
}
int getstacklevel()
/* returns the last empty line in the virtual field */
{
int y = PLM_TOP;
while(isempty(y))
y--;
return(y);
}
int isempty(y)
int y;
{
int x;
for(x = 0; x < VIRT_XSIZE; x++)
if(field[x][y] != CLEAR)
return(FALSE);
return(TRUE);
}
int reset_f()
{
int x,y;
for(x = 0; x < VIRT_XSIZE;x++)
for(y = 0; y < VIRT_YSIZE;y++)
f[x][y] = CLEAR;
}